package com.zhdl.hardware.clamping_jaw.micro.repository.impl;

import com.project.command.faq.event.behavior.BehaviorPerform;
import com.zhdl.hardware.clamping_jaw.micro.repository.MicroPortCmdHandleDao;
import com.zhdl.modules.tools.CommonCallback;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Slf4j
@Component
public class MicroPortCmdHandleDaoImpl implements MicroPortCmdHandleDao {
    @Resource
    public BehaviorPerform behaviorPerform;
    public Map<String, MicroCmdHandleDaoImpl> daoMap = new ConcurrentHashMap<>();

    /**
     * 添加串口
     *
     * @param port 串口号
     */
    @Override
    public void addPort(String port) {
        MicroCmdHandleDaoImpl microCmdHandleDao = new MicroCmdHandleDaoImpl(port, behaviorPerform);
        daoMap.put(port, microCmdHandleDao);
    }

    @Override
    public void microGenericCmd(String port, String cmd, CommonCallback<byte[]> callback){
        daoMap.get(port).microGenericCmd(cmd, callback);
    }
}
